# from bs4 import BeautifulSoup
# import lxml
#
# with open('index_practice.html', 'r', encoding='utf-8') as html_file:
#     soup = BeautifulSoup(html_file, "lxml")
###################################################
# from bs4 import BeautifulSoup
# import lxml
#
# def main():
#     with open ('index1_for_4_step.html', 'r', encoding='utf-8') as html_doc:
#         soup = BeautifulSoup(html_doc,  "lxml")
#     p_description = soup.find("p", class_="card-description")
#     print(p_description.text)
# main()
###################################################

# from bs4 import BeautifulSoup
# import lxml
#
# def main():
#     with open('index4_for_task.html', 'r', encoding='utf-8') as html_doc:
#         soup = BeautifulSoup(html_doc,  "lxml")
#     articuls = [int(tag.text.split(':')[-1])
#                 for tag in soup.find_all('p', class_='card-articul')]
#     sum_articuls = sum(articuls)
#     print(f"Сумма артикулов: {sum_articuls}")
#
# main()
####################################################
# from bs4 import BeautifulSoup
# import lxml
#
# def main():
#     # Инициализация объекта BeautifulSoup
#     with open('index2_for_task.html', 'r', encoding='utf-8') as html_doc:
#         soup = BeautifulSoup(html_doc,  "lxml")
#
#     # Находим все теги img
#     img_tags = [int(x.attrs['alt']) for x in soup.find_all('img')]
#
#     # Извлекаем значения атрибута alt и суммируем их
#     total_sum = sum(img_tags)
#
#     print(f"Сумма всех значений в атрибуте alt тега img: {total_sum}")
#
# main()
####################################################
import requests
from bs4 import BeautifulSoup

url = 'https://parsinger.ru/4.3/4/index.html'
response = requests.get(url)
response.encoding = 'utf-8'
html = response.text

def len_string_without_space(string):
    return len(string) - string.count(' ')

def sum_even_length_ids(html):
    soup = BeautifulSoup(html, 'html.parser')

    p_even_length = [x for x in soup.find_all('p')
                     if len_string_without_space(x.text) % 2 == 0]

    total_id_sum = sum([int(x.attrs.get('id')) for x in p_even_length])
    total_class_sum = sum([int(x.attrs.get('class')[0]) for x in p_even_length])

    print(f"Сумма ID и CLASS тегов <p> с чётной длиной текста без пробелов: {total_id_sum + total_class_sum}")

sum_even_length_ids(html)
